package org.phpgwt.tester.client.tests;

import org.phpgwt.tester.client.remote.StringTestService;
import org.phpgwt.tester.client.remote.StringTestServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class StringTest extends PhpGwtTest {
	private static StringTestServiceAsync service = GWT.create(StringTestService.class);
	private static String str = "";

	public static void run() {
		for (int i = 0; i < 65536; i++) {
			str += Character.toString((char) (i % 256));
		}

		service.getString(new AsyncCallback<String>() {
			public void onSuccess(String result) {
				printResult("getString", result, "phpgwt rocks");
			}

			public void onFailure(Throwable caught) {
				printResult("getString", caught);
			}
		});

		service.sendString("phpgwt rocks", new AsyncCallback<Boolean>() {
			public void onSuccess(Boolean result) {
				printResult("sendString", result, true);
			}

			public void onFailure(Throwable caught) {
				printResult("sendString", caught);
			}
		});

		service.getUTF8String(new AsyncCallback<String>() {
			public void onSuccess(String result) {
				printResult("getUTF8String", result, str);
			}

			public void onFailure(Throwable caught) {
				printResult("getUTF8String", caught);
			}
		});

		service.sendUTF8String(str, new AsyncCallback<Integer>() {
			public void onSuccess(Integer result) {
				printResult("sendUTF8String", result, 0);
			}

			public void onFailure(Throwable caught) {
				printResult("sendUTF8String", caught);
			}
		});
	}
}
